﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InsuranceCompany.Core.Domain.InsuranceArea
{
    public class InsuranceType :InsuranceEntity
    {
        public string Name { get; set; }
        private int minContractTime;
        public int	MinContractTime 
        { 
            get
            {
                return minContractTime;
            }
            set
            {
                this.resetErrorMessage();
                if (value <= 0)
                {
                    this.setErrorMessage("Minimal time must be positive!");
                    return;
                }
                if ((value > MaxContractTime) && (MaxContractTime != 0))
                {
                    this.setErrorMessage("Minimal time can't be greater than maximal time!");
                    return;
                }
                minContractTime = value;
            }
        }
        private int maxContractTime;
        public int	MaxContractTime 
        { 
            get
            {
                return maxContractTime;
            }
            set
            {
                this.resetErrorMessage();
                if (value <= 0)
                {
                    this.setErrorMessage("Maximal time must be positive!");
                    return;
                }
                maxContractTime = value;
            }
        }
        public Decimal RiskMaxSum { get; set; }
        public Decimal MinCost { get; set; }

        private InsuranceRisks Risks;

        public InsuranceType() :base()
        {
            Name = "No name";
            MinContractTime = 1;
            MaxContractTime = 1;
            RiskMaxSum = 0.0M;
            MinCost = 0.0M;
            Risks = new InsuranceRisks();
        }

        public InsuranceType(InsuranceType it)
            : base(it)
        {
            Name = it.Name;
            MinContractTime = it.MinContractTime;
            MaxContractTime = it.MaxContractTime;
            RiskMaxSum = it.RiskMaxSum;
            MinCost = it.MinCost;
            Risks = new InsuranceRisks(it.GetRisks());
        }

        public InsuranceType(string name, int minContractTime, int maxContractTime, 
                             Decimal riskMaxSum, Decimal minPayment, List<InsuranceRisk> risks)
            : base()
        {
            Name = name;
            MinContractTime = minContractTime;
            MaxContractTime = maxContractTime;
            RiskMaxSum = riskMaxSum;
            MinCost = minPayment;
            Risks = new InsuranceRisks(risks);
        }

        public Decimal CalculateMinSum() { return this.Risks.CalculateMinSum(); }
        public InsuranceRisks GetInsuranceRisks() { return this.Risks; }
        public void AddRisk(InsuranceRisk risk) { this.Risks.AddRisk(risk); }
        public void AddRisks(List<InsuranceRisk> risks) { Risks.AddRisks(risks); }
        public void ReplaceRisks(InsuranceRisks risks)
        {
            Risks.ReplaceRisks(risks);
        }
        public void ReplaceRisks(List<InsuranceRisk> risks)
        {
            Risks.ReplaceRisks(risks);
        }
        public Decimal GetMinTypeSum() { return Risks.CalculateMinSum(); }
        public InsuranceRisks GetRisks () { return this.Risks; }
        public InsuranceRisk GetRisk (int riskIndex) { return Risks.GetRisk(riskIndex); }
        public bool ContainsRisk(InsuranceRisk risk) { return this.Risks.ContainsRisk(risk); }
        public void DeleteRisk(int riskIndex) { this.Risks.DeleteRisk(riskIndex); }
        public void DeleteAllRisks() { this.Risks.DeleteAll(); }



        
    }
}
